home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Developer Essentials / DTS Sample Code / Snippets / Nets & Comm / Get Tool Config / GetToolConfig.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-09  |  3.2 KB  |  117 lines  |  [TEXT/KAHL]

  1. /*
  2.     Get Tool Config
  3.     ©1991 Apple Computer Inc.
  4.     By    Apple Developer Tech Support
  5.     
  6.     Description:
  7.         This q&d allows one to accumulate into a TEXT file the config strings 
  8.         of Connection Tools that have been configured with CMChoose.
  9.     
  10.     Build Instructions:
  11.         Used with THINK C v5.0, project setup:
  12.             seg1: GetToolConfig.c, MacTraps, CommToolbox
  13.             seg2: ANSI
  14.  
  15.     Change History:
  16.     
  17.     8/10/91        Godfrey DiGiorgi    created this bugger from some existing source lying about
  18.     8/30/91     Godfrey DiGiorgi    fixed it up to be useful
  19. */
  20. #include <Traps.h>
  21. #include <stdio.h>
  22. #include <CommResources.h>
  23. #include <Connections.h>
  24.  
  25. // function prototypes
  26. void main(void);
  27.  
  28. void main() {
  29.     short           procID;
  30.     ConnHandle      connection;
  31.     CMBufferSizes   bufSizes;
  32.     OSErr           err;
  33.     Str255          toolName;
  34.     Point           where;
  35.     short           result;
  36.     Ptr             configStream;
  37.     FILE*           fp;
  38.     
  39.     // putting something into TTY window initializes QD globals, etc.
  40.     printf("•• running Get Tool Config program ••\n\n");
  41.     
  42.     // initialize CTB and managers
  43.     if (NGetTrapAddress(_CommToolboxDispatch, OSTrap) ==
  44.         NGetTrapAddress(_Unimplemented, OSTrap)) {
  45.         printf("•• CTB Not available ••\n");
  46.         return;
  47.     }
  48.     if (noErr != InitCRM()) {
  49.         printf("•• CTB Available but InitCRM failed. ••\n");
  50.         return;
  51.     }
  52.     if (noErr != InitCTBUtilities()) {
  53.         printf("•• CTB Available: InitCTBUtilities Fail. ••\n");
  54.         return;
  55.     }
  56.     if (cmNoTools == InitCM()) {
  57.         printf("•• CTB Available: No connection tools found. ••\n");
  58.         return;
  59.     }
  60.     
  61.     // get a Connection Tool name
  62.     err = CRMGetIndToolName('cbnd',1,toolName);
  63.     if (err != noErr) {
  64.         printf("•• CRMGetIndToolName failed... no Conn Tool available ?!?!? ••\n");
  65.         return;
  66.     }
  67.     // get a resource ID for it
  68.     procID = CMGetProcID(toolName);
  69.     if (-1 == procID) {
  70.         printf("•• CMGetProcID: No 'Apple (ISDN) Serial Tool'. ••\n");
  71.         return;
  72.     }
  73.     
  74.     // init the CMBufferSizes variable so that Tool will init with defaults
  75.     bufSizes[cmDataIn] = 0;
  76.     bufSizes[cmDataOut] = 0;
  77.     bufSizes[cmCntlIn] = 0;
  78.     bufSizes[cmCntlOut] = 0;
  79.     bufSizes[cmAttnIn] = 0;
  80.     bufSizes[cmAttnOut] = 0;
  81.     
  82.     // now get a conn record set up 
  83.     connection = CMNew(procID, cmData|cmNoMenus|cmQuiet, bufSizes, 0, 0);
  84.     if (connection == nil) {
  85.         printf("•• CMNew: Can't create a CTB connection record. ••\n");
  86.         return;
  87.     }
  88.     
  89.     // CMChoose Dialog has to hang off this point (global coordinates)
  90.     SetPt(&where,20,40);
  91.     // now do CMChoose et al:
  92.     result = CMChoose(&connection,where,NULL);
  93.     if ((result == chooseOKMajor) || (result == chooseOKMinor)) {
  94.         configStream = CMGetConfig(connection);
  95.         if (configStream == NULL) {
  96.             printf("CMGetConfig failed\n\n");
  97.         } else {
  98.             CMGetToolName((**connection).procID,toolName);
  99.             PtoCstr(toolName);
  100.             printf("• Configuration string for %s:\n'%s'\n\n",toolName, configStream);
  101.             fp = fopen("Tool Configs","a");
  102.             if (fp != NULL) {
  103.                 fprintf(fp,"• Configuration string for %s:\n'%s'\n\n",toolName, configStream);
  104.                 fclose(fp);
  105.                 printf("•• Configuration string info appended to file 'Tool Configs'. ••\n\n");
  106.             } else {
  107.                 printf("•• Output file could not be opened. ••\n");
  108.             }
  109.             DisposPtr(configStream);
  110.         }
  111.     } else {
  112.         printf("•• CMChoose failed. ••\n");
  113.     }
  114.     CMDispose(connection);
  115.     printf("•• closing Get Tool Config program ••\n\n");
  116. }
  117.